import 'context.dart';
import 'scope.dart';

import 'mixins.dart';

/// Data Access Layer (DAL) repository.
/// A DAL repository is a context that can be used to manage resources
/// and provide data access functionality.
abstract class DalRepository extends DalContext with DalDisposable {
  DalScope scope;

  DalRepository(this.scope);

  /// Creates the DAL repository.
  /// This method should be called when the DAL repository is created.
  @override
  void onCreate() {
    super.onCreate();
    registerSelf();
  }

  /// Registers the DAL repository in the scope.
  void registerSelf() {
    scope.registerRepo(this);
  }

  /// Initializes the DAL repository.
  /// This method should be called after the DAL repository is created.
  /// It is important to initialize resources to prevent memory leaks.
  @override
  Future<bool> onInit() async {
    return await super.onInit();
  }

  /// Cleans up resources when the DAL repository is reseted.
  @override
  Future<bool> onReset() async {
    return await super.onReset();
  }

  /// Cleans up resources when the DAL repository is destroied.
  @override
  void onDisposed() {
    scope.unregisterRepo(this);
    dalDispose();
    super.onDisposed();
  }
}
